package com.yikaiye.android.yikaiye.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.DataBindingHolder;
import com.yikaiye.android.yikaiye.R;
import com.yikaiye.android.yikaiye.databinding.ItemGsInfoBinding;
import com.yikaiye.android.yikaiye.model.company.GsInfoAllModel;

/**
 * 工商信息
 */
public class GsBaseInfoAdapter extends BaseQuickAdapter<GsInfoAllModel, DataBindingHolder<ItemGsInfoBinding>> {

    private final Context context;

    public GsBaseInfoAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected void onBindViewHolder(@NonNull DataBindingHolder<ItemGsInfoBinding> itemGsInfoBindingDataBindingHolder, int position, @Nullable GsInfoAllModel model) {
        ItemGsInfoBinding binding = itemGsInfoBindingDataBindingHolder.getBinding();
        if (model != null) {
            switch (position) {
                case 0: // 基本信息
                    binding.recyclerView.setAdapter(new CompanyIntroAdapter(context, model.getInfoList()));
                    break;
                case 1: // 股东信息
                    GdInfoAdapter gdInfoAdapter = new GdInfoAdapter();
                    gdInfoAdapter.setEmptyViewEnable(true);
                    gdInfoAdapter.setEmptyViewLayout(context, R.layout.layout_empty_list2);
                    gdInfoAdapter.submitList(model.getPartnersAlls());
                    binding.recyclerView.setAdapter(gdInfoAdapter);
                    break;
                case 2: // 主要人员
                    MainPersonInfoAdapter mainPersonInfoAdapter = new MainPersonInfoAdapter();
                    mainPersonInfoAdapter.setEmptyViewEnable(true);
                    mainPersonInfoAdapter.setEmptyViewLayout(context, R.layout.layout_empty_list2);
                    mainPersonInfoAdapter.submitList(model.getEmployeesAlls());
                    binding.recyclerView.setAdapter(mainPersonInfoAdapter);
                    break;
                case 3: // 工商变更
                    GsChangeAdapter gsChangeAdapter = new GsChangeAdapter(context);
                    gsChangeAdapter.setEmptyViewEnable(true);
                    gsChangeAdapter.setEmptyViewLayout(context, R.layout.layout_empty_list2);
                    gsChangeAdapter.submitList(model.getRecords());
                    binding.recyclerView.setAdapter(gsChangeAdapter);
                    break;
                case 4: // 企业年报
                    ReportAdapter reportAdapter = new ReportAdapter();
                    reportAdapter.setEmptyViewEnable(true);
                    reportAdapter.setEmptyViewLayout(context, R.layout.layout_empty_list2);
                    reportAdapter.submitList(model.getReportDetails());
                    binding.recyclerView.setAdapter(reportAdapter);
                    break;
            }
            binding.llContainer.setBackgroundResource(model.isOpen() ? R.drawable.shape_stroke_3d90f2_4dp : R.drawable.shape_stroke_ffffff_4dp);
            binding.recyclerView.setVisibility(model.isOpen() ? View.VISIBLE : View.GONE);
            binding.ivArrow.setImageResource(model.isOpen() ? R.mipmap.icon_top_arrow : R.mipmap.icon_down2);
            binding.tvTitle.setText(model.getTitle());
            binding.tvTitle.setTextColor(ContextCompat.getColor(context, model.isOpen() ? R.color.color_3d90f2 : R.color.color_3b3a40));
            binding.iv.setImageResource(model.getIcon());

            binding.llTitle.setOnClickListener(view -> {
                model.setOpen(!model.isOpen());
                notifyItemChanged(itemGsInfoBindingDataBindingHolder.getAbsoluteAdapterPosition());
            });
        }
    }

    @NonNull
    @Override
    protected DataBindingHolder<ItemGsInfoBinding> onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup viewGroup, int i) {
        return new DataBindingHolder<>(R.layout.item_gs_info, viewGroup);
    }
}
